<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员登录 - 连连看游戏系统</title>
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <style>
        /* 管理员专属配色 */
        body {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
        }

        .login-container {
            max-width: 450px;
            margin: 0 auto;
        }
        
        .admin-badge {
            display: inline-block;
            background: rgba(240, 147, 251, 0.2);
            color: white;
            padding: 8px 20px;
            border-radius: 20px;
            margin-bottom: 30px;
            font-size: 14px;
            font-weight: 600;
            letter-spacing: 1px;
        }
        
        .card-title {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .btn-primary {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            box-shadow: 0 4px 12px rgba(240, 147, 251, 0.3);
        }

        .btn-primary:hover {
            box-shadow: 0 6px 20px rgba(240, 147, 251, 0.4);
        }

        .form-control:focus {
            border-color: #f093fb;
            box-shadow: 0 0 0 3px rgba(240, 147, 251, 0.1);
        }

        .text-link:hover {
            color: #f5576c;
        }

        .admin-icon {
            font-size: 64px;
            text-align: center;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <div class="page-header">
        <h1>👑 管理员控制台</h1>
        <p class="subtitle">欢迎回来，请登录以继续</p>
    </div>

    <div class="container">
        <div class="login-container">
            <div class="card">
                <div class="admin-icon">🔐</div>
                <div class="text-center">
                    <span class="admin-badge">ADMINISTRATOR</span>
                </div>
                
                <h2 class="card-title">管理员登录</h2>
                
                <div id="alertMessage" class="alert"></div>
                
                <form id="loginForm">
                    <div class="form-group">
                        <label for="username">管理员账号 <span class="required">*</span></label>
                        <input type="text" 
                               id="username" 
                               name="username" 
                               class="form-control" 
                               placeholder="请输入管理员账号"
                               required>
                    </div>
                    
                    <div class="form-group">
                        <label for="password">密码 <span class="required">*</span></label>
                        <input type="password" 
                               id="password" 
                               name="password" 
                               class="form-control" 
                               placeholder="请输入密码"
                               required>
                    </div>
                    
                    <button type="submit" class="btn btn-primary btn-block" id="loginBtn">
                        登录控制台
                    </button>
                </form>
                
                <div class="text-center" style="margin-top: 20px;">
                    <a th:href="@{/user/login}" class="text-link">← 返回用户登录</a>
                </div>
            </div>
        </div>
    </div>

    <footer class="page-footer">
        <p>&copy; 2025 连连看游戏系统管理控制台. All rights reserved.</p>
        <p>安全、可靠、专业的管理平台</p>
    </footer>

    <script>
        // 登录表单提交
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value;
            
            if (!username || !password) {
                showAlert('请填写完整的登录信息', 'error');
                return;
            }
            
            const loginBtn = document.getElementById('loginBtn');
            loginBtn.disabled = true;
            loginBtn.innerHTML = '<span class="loading"></span> 验证中...';
            
            // 发送登录请求
            fetch('/admin/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    username: username,
                    password: password
                })
            })
            .then(response => response.json())
            .then(data => {
                if (data.code === 200) {
                    showAlert('登录成功！正在跳转...', 'success');
                    setTimeout(() => {
                        window.location.href = '/admin/home';
                    }, 1000);
                } else {
                    showAlert(data.message || '登录失败', 'error');
                    loginBtn.disabled = false;
                    loginBtn.innerHTML = '登录控制台';
                }
            })
            .catch(error => {
                console.error('Error:', error);
                showAlert('网络错误，请稍后重试', 'error');
                loginBtn.disabled = false;
                loginBtn.innerHTML = '登录控制台';
            });
        });
        
        // 显示提示信息
        function showAlert(message, type) {
            const alertDiv = document.getElementById('alertMessage');
            alertDiv.className = `alert alert-${type} show`;
            alertDiv.textContent = message;
            
            setTimeout(() => {
                alertDiv.className = 'alert';
            }, 5000);
        }

        // 测试数据提示（开发环境）
        console.log('管理员测试账号: admin / admin123');
    </script>
</body>
</html>
